package de.softcon.sc4retail.ui;

import de.softcon.sc4retail.R;
import de.softcon.sc4retail.R.id;
import de.softcon.sc4retail.R.menu;
import de.softcon.sc4retail.R.string;
import de.softcon.sc4retail.domainmodel.ShoppingCart;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;

public class OptionMenuPlugin extends Activity {

	
	/**
	 * Creates the options menu for the shop view.
	 */
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
	    MenuInflater inflater = getMenuInflater();
	    inflater.inflate(R.menu.shopgallerymenu, menu);
	    return true;
	}
	
	/**
	 * Handles menu selection
	 */
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
	    // Handle menu item selection
	    switch (item.getItemId()) 
	    {
		    case R.id.showCart:
		    {
		    	//If the shopping cart is empty do not allow checkout
		    	if(ShoppingCart.getInstance().isEmpty())
		    	{
		    		Toast.makeText(OptionMenuPlugin.this, R.string.emptyCart, Toast.LENGTH_SHORT).show();
		    		return false;
		    	}
		    	else
		    	{		    		
			    	startActivity(new Intent(OptionMenuPlugin.this, ShoppingCartDialog.class));
			        return true;		    	
		    	}
		    }
		    case R.id.checkout:
		    {
		    	//If the shopping cart is empty do not allow checkout
		    	if(ShoppingCart.getInstance().isEmpty())
		    	{
		    		Toast.makeText(OptionMenuPlugin.this, R.string.emptyCart, Toast.LENGTH_SHORT).show();
		    		return false;
		    	}
		    	else
		    	{
			    	Log.d(this.getClass().toString(), "Proceeding to checkout & payment");
			    	startActivity(new Intent(OptionMenuPlugin.this, CheckoutDialog.class));
			        return true;		    			    		
		    	}
		    }
		    case R.id.categories:
		    {
		    	//TODO proceed to the checkout page
		        return true;		    	
		    }
		    default:
		        return super.onOptionsItemSelected(item);
	    }
	}
}
